﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Noodles.Core.Repositories;
using Noodles.Core.Model;
using Noodles.Core.Enums;
using NoodlesCms.Configuration.Extensions;

namespace NoodlesCms.Areas.Admin.Controllers
{
    public class AdminController : Controller
    {
        //
        // GET: /Admin/Admin/
      
        public NHibernateRepository repository { get; set; }
        public INoodlesRepository adminRepo { get; set; }

        public ActionResult Index()
        {
            if (Session["adminid"] == null)
            {
               return RedirectToAction("Index","Login", new { area = "Admin" });
            }
            var blogs = adminRepo.GetPagedBlog("Home",1,5);
            return View(blogs);
        }
        public ActionResult BlogList(int page)
        {
            var blogs = adminRepo.GetPagedBlog("Home", page, 5);
            return PartialView(blogs);
        }
        //
        // GET: /Admin/Admin/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Admin/Admin/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Admin/Admin/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /Admin/Admin/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Admin/Admin/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Admin/Admin/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Admin/Admin/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
